﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace r2mp_Excel
{
    public partial class AddDialog : Form
    {
        //This delegate is for the communication between the AddDialog and the Dialog Class.
        public delegate void AddItem(string item);

        AddItem add;

        public AddItem Add
        {
            set { add = value; }
        }

        //These 2 constants are meant to be used for the constuctor of the Adddialog class.
        public const int MTA = 0;
        public const int PSP = 1;

        private string[] mtaTypes = { "Name", "Enddatum", "Kontrolldatum" };
        private string[] pspTypes = { "Name", "Nr", "Dauer", "Fertigstellung", "Ressourcen" };

        public AddDialog(int mode)
        {
            InitializeComponent();
            switch (mode)
            {
                case 0:
                    cbType.Items.AddRange(mtaTypes);
                    break;
                case 1:
                    cbType.Items.AddRange(pspTypes);
                    break;
            }
            cbType.SelectedIndex = 0;
        }

        public AddDialog(int mode,string item)
        {
            InitializeComponent();
            switch (mode)
            {
                case 0:
                    cbType.Items.AddRange(mtaTypes);
                    break;
                case 1:
                    cbType.Items.AddRange(pspTypes);
                    break;
            }
            string[] temp = item.Split(':');
            tbName.Text = temp[1];
            cbType.SelectedItem = temp[0];
        }



        private void AddDialog_Load(object sender, EventArgs e)
        {

        }

        private void bAdd_Click(object sender, EventArgs e)
        {
            if (!tbName.Text.Equals("") && cbType.SelectedIndex >= 0)
            {
                add(cbType.SelectedItem + ":" + tbName.Text);
                this.Close();
            }
        }

        private void bCancle_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
